package jmm;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName jmm03
 * @date 2021/4/1 13:57
 * @Version 1.0
 * @Description //这是jmm查看八大原子操作例子
 * @USER root
 */
@Slf4j
public class jmm01 {
    private static final Logger LOGGER = LoggerFactory.getLogger(jmm01.class);

    public static volatile Boolean initFlag = false;
    public static volatile int count = 0;
    public static void refresh(){
        System.out.println("refresh data.......");
        initFlag = true;
        System.out.println("refresh data success.......");
    }

    public static void main(String[] args) {
        Thread threadA = new Thread(()->{
            while (!initFlag) {
                System.out.println("runging。。。");
//                count++;
            }
            System.out.println("线程："+Thread.currentThread().getName()+"当前initflag状态改变");
        },"ThreadA");
        threadA.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
         e.printStackTrace();
        }
        Thread threadB = new Thread(()->{
            refresh();
        },"ThreadB");
        threadB.start();
    }

}
